1 package junit.quilt.ui.jips;
2
3 import java.awt.Component;
4 import java.awt.GridLayout;
5 import java.awt.BorderLayout;
6
7 import java.util.Map;
8 import java.util.Timer;
9 import java.util.HashMap;
10 import java.util.TimerTask;
11
12 import javax.swing.*;
13 import javax.swing.tree.*;
14 import javax.swing.event.*;
15
16 import junit.quilt.util.*;
17
18 import junit.quilt.cover.ball94.*;
19
20 public class JipsPanel
21 extends JPanel
22 implements RegistryBrowserAware
23 {
24 private RegistryBrowser browser = null;
25 //private JPanel outputPanel = new JPanel();
26 private JProgressBar progress = new JProgressBar();
27 private Timer sched = new Timer(true);
28
29 private B94Registry registry = null;
30 //private B94Collector b94c = null;
31 //private int instLengths[] = null;
32
33 private TreeSL listener = null;
34
35 //private Map lastReadTime = new HashMap(); // Collector X Time
36 //private Map lastReadScore = new HashMap(); // Collector X Value
37
38 private class Updater extends TimerTask
39 {
40 private JipsPanel jips = null;
41
42 public Updater( JipsPanel jips ) {
43 this.jips = jips;
44 }
45
46 public void run() {
47 jips.updateScore();
48 }
49 }
50
51 private class TreeSL implements TreeSelectionListener
52 {
53 private JipsPanel jips = null;
54
55 public TreeSL( JipsPanel jips ) {
56 this.jips = jips;
57 }
58
59 public void valueChanged( TreeSelectionEvent tse ) {
60 if (tse.getPath() != null) {
61 if (registry.getCollector( tse.getPath() ) != null) {
62 jips.changeCollector((B94Collector) registry.
63 getCollector(tse.getPath()));
64 }
65 }
66 }
67 }
68
69 public JipsPanel() {
70 setLayout( new BorderLayout() );
71 listener = new TreeSL( this );
72
73 progress.setMinimum( 0 );
74 progress.setMaximum( 1000 );
75
76 JPanel north = new JPanel( new BorderLayout() );
77 north.add( new JLabel("JIPS (x 10000)"),
78 BorderLayout.WEST );
79 north.add( progress, BorderLayout.CENTER );
80
81 add( north, BorderLayout.NORTH );
82 add( new JPanel(), BorderLayout.CENTER );
83
84 TimerTask updater = new Updater( this );
85 sched.schedule( updater, 50, 50 );
86 }
87
88 public void changeCollector( B94Collector collector ) {
89 // b94c = collector;
90 // instLengths = b94c.getInstructionLengths();
91 }
92
93
94 public void updateScore() {
95 // if (b94c == null) return;
96
97 // int data[] = b94c.newStats();
98
99 // long thisTime = b94c.getStats( data );
100 // long thisScore = 0;
101
102 // for (int i = 0; i < data.length; i++) {
103 // thisScore += instLengths[i] * data[i];
104 // }
105
106 // long lastTime = 0;
107 // long lastScore = 0;
108
109 // if (lastReadTime.containsKey( b94c )) {
110 // lastTime = ((Long) lastReadTime.get( b94c ))
111 // .longValue();
112 // lastReadTime.remove( b94c );
113 // }
114 // lastReadTime.put( b94c, new Long( thisTime ));
115
116
117 // if (lastReadScore.containsKey( b94c )) {
118 // lastScore = ((Long) lastReadScore.get( b94c ))
119 // .longValue();
120 // lastReadScore.remove( b94c );
121 // }
122
123 // lastReadScore.put( b94c, new Long( thisScore ) );
124
125 // double rate =
126 // (double) (thisScore - lastScore) /
127 // (double) (thisTime - lastTime) *
128 // 1000.00;
129
130 // Double RC = new Double( rate / 100000 );
131 // progress.setValue( RC.intValue() );
132 }
133
134 public void setRegistryBrowser( RegistryBrowser browser ) {
135 this.browser = browser;
136 this.registry = (B94Registry) browser.getRegistry();
137 browser.getTree().addTreeSelectionListener( listener );
138 }
139 }
This page was automatically generated by Maven